<template>
  <nav class="navbar">
    <div class="navbar-container">
      <router-link to="/" class="logo">羽你有约</router-link>
      <ul class="nav-links">
        <li><router-link to="/">首页</router-link></li>
        <li><router-link to="/news">羽毛球新闻</router-link></li>
        <li><router-link to="/community">交流社区</router-link></li>
        <li><router-link to="/second-hand">二手交易</router-link></li>
        <li><router-link to="/court-booking">场地预约</router-link></li>
        <li><router-link to="/playing-appointment">约球活动</router-link></li>
        <li><router-link to="/video-tutorials">视频教学</router-link></li>
        <li><router-link to="/match-replays">比赛回放</router-link></li>
        <li><router-link to="/reviews">测评</router-link></li>
        <li><router-link to="/equipment-auth">装备鉴定</router-link></li>
        <li><router-link to="/points">会员积分</router-link></li>
      </ul>
      <div class="user-actions">
        <span v-if="isLoggedIn">{{ currentUser.username }}</span>
        <router-link to="/login" v-else class="login-btn">登录/注册</router-link>
        <button v-if="isLoggedIn" @click="logout" class="logout-btn">退出</button>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { computed } from 'vue';

const store = useStore();
const router = useRouter();

const isLoggedIn = computed(() => store.getters.isLoggedIn);
const currentUser = computed(() => store.getters.currentUser);

const logout = () => {
  store.dispatch('logout');
  router.push('/login');
};
</script>

<style scoped>
.navbar {
  background: linear-gradient(135deg, #4CAF50 0%, #2196F3 100%);
  padding: 0.5rem 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
}

.logo {
  color: white;
  font-size: 1.8rem;
  font-weight: bold;
  text-decoration: none;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
}

.nav-links a {
  color: white;
  text-decoration: none;
  padding: 0.5rem 0;
  position: relative;
}

.nav-links a:after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: white;
  transition: width 0.3s ease;
}

.nav-links a:hover:after {
  width: 100%;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: white;
}

.login-btn,
.logout-btn {
  background-color: white;
  color: #2196F3;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.logout-btn {
  background-color: #f44336;
  color: white;
}
</style>